import requests
import time,datetime
def get_current_time(add=0, timedelta='hours'):
    '''
    :param days: 正整数就加天数，负就相反
    :return: 返回字符串格式时间
    '''
    if add == 0:
        now = int(time.time())
        # 转换为其他日期格式,如:"%Y-%m-%d %H:%M:%S"
        timeArray = time.localtime(now)
        otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)

        return otherStyleTime
    else:
        # 选择当前时间的天、时、分的前推或者后退
        if timedelta == 'days':
            return (datetime.datetime.now() + datetime.timedelta(days=add)).strftime("%Y-%m-%d %H:%M:%S")
        if timedelta == 'hours':
            return (datetime.datetime.now() + datetime.timedelta(hours=add)).strftime("%Y-%m-%d %H:%M:%S")
        if timedelta == 'minutes':
            return (datetime.datetime.now() + datetime.timedelta(minutes=add)).strftime("%Y-%m-%d %H:%M:%S")

def zi_yin_token(username,password):
    '''
    :param username: 用户名
    :param password: 密码
    :return: 自营平台token
    '''
    headers1={'accept':'application/json, text/plain, */*'}
    response=requests.post('https://uapi.keking.cn:8001/yudian_authz/oauth/token?username={}&password={}&client_id'
                       '=authz&client_secret=authz&grant_type=password&scope=read write'.format(username,password),headers1)
    return response.json()["access_token"]
def get_zi_yin(name='gaoxiaobo',pwd='Gqy901010'):
    token = zi_yin_token(name, pwd)
    headers = {'content-type': 'application/json;charset=UTF-8',
               'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36',
               'token': token + '-' + name}
    return {'ip': 'http://kk-self-business.uat-ingress.keking.cn', 'headers': headers}